#ifndef FTPSERVICER_H
#define FTPSERVICER_H

#include "Socket.h"
#include "LineStream.h"
#include "FtpCommandObserver.h"
#include "FtpCommandParser.h"
#include "AccountManager.h"
#include "FilePath.h"
#include "DataConnectionObserver.h"
#include "DataConnection.h"

class FtpServicer: public FtpCommandObserver, public DataConnectionObserver
{
public:


	FtpServicer(const Socket& control, const AccountManager& manager, const FilePath& ftproot);
	~FtpServicer();

	void MainLoop();

private:
	LineStream lineStream;
	std::string dataip;
	unsigned short dataport;
	bool authenticated;
	FilePath rootpath, sessionpath;
	Socket controlSocket;
	FtpCommandParser commandParser;
	DataConnection dataConnection;
	AccountManager accountManager;
	Account account;



	FtpServicer(); // no default constructor
	FtpServicer(const FtpServicer& rhs); // no copy constructor

	bool CheckLoggedIn();
	FilePath ExtendSessionPath(const std::string& extension);
	FilePath FullSessionPath(const FilePath& sessionpath);
	void SendReply(unsigned int code, const std::string& reason);
	void StartUpload();
	void StartDownload();
	void UploadData(const void* data, unsigned int size);
	void ReadControlData();
	void SetDownloadSink(const std::string& path);
	void SetUploadSource(const std::string& path);

	void OnUser(const std::string& user);
	void OnPass(const std::string& pass);
	void OnList(const std::string& list);
	void OnSyst();
	void OnPort(const std::string& ip, unsigned short port);
	void OnCwd(const std::string& cwd);
	void OnPwd();
	void OnRmd(const std::string& path);
	void OnMkd(const std::string& path);
	void OnDele(const std::string& path);
	void OnRetr(const std::string& path);
	void OnStor(const std::string& path);
	void OnCdup();
	void OnNoop();
	void OnQuit();
	void OnType(const std::string& type);
	void OnSyntaxError();
	void OnUnknownCommand();

	void OnDataConnectError();
	void OnDataStarted();
	void OnDataEnded();
	void OnDataSinkError();
	void OnDataSourceError();
	

};

#endif // FTPSERVICER_H

